#ifndef MAINHANDLER_H
#define MAINHANDLER_H




class MainHandler : public Handler 
{
public:
	MainHandler(MainView * mainView, Model * model)
		:mainView(mainView), model (model){}
	~MainHandler(){}

public:
	int  create() 
	{
		/*
		MessageBox(
			NULL,
			(LPCWSTR)L"Resource not available\nDo you want to try again?",
			(LPCWSTR)L"Account Details",
			MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2
			);
		*/
		return 0;
		
	}
	int keyUp(int key, LPARAM lParam)
	{
		//Broadcast message to all the child windows. The WM_KEYUP messages cannot 
		// be received directly by child windows. 
		//::EnumChildWindows(handle, (WNDENUMPROC)enumerateChildren, (LPARAM)WM_KEYUP);     
		//So we switch the mode here
		switch (key)
		{
		case VK_TAB:
			if (model->mappingView.viewMode == EDIT)
			{
				model->mappingView.viewMode = VIEW ;
				model->cullingView.viewMode = VIEW ;
				model->mappingView.lbf = TRANSLATE ;
				//model->cullingView.lbf = TRANSLATE ;

			} else
			{
				model->mappingView.viewMode = EDIT ;
				model->cullingView.viewMode = EDIT ;
				model->mappingView.lbf = PAINT ;
			}
			model->mappingView.updated = true;
			model->cullingView.updated = true;
			break;
		case 0x52 : //Key R
			model->mappingView.lbf = ROTATE ;
			break;
		case 0x54 : //Key T
			model->mappingView.lbf = TRANSLATE ;
			break;
		case 0x55 : //Key U upsampling ;
			if (model->mappingView.viewMode == EDIT)
			{
				model->upSampling () ;
				model->mappingView.updated = true;
				model->cullingView.updated = true;
			}
			break;
		case 0x44 : //Key D downsampling ;
			if (model->mappingView.viewMode == EDIT)
			{
				model->downSampling ();
				model->mappingView.updated = true; 
				model->cullingView.updated = true;
			}
			break;
		default :
			;
		}
		return 0;
	}

	/*
	static bool CALLBACK enumerateChildren(HWND handle, LPARAM lParam)
	{
		if(lParam == WM_KEYUP)
		{
			//Fixme here, I cannot pass the value of KEY.
			::SendMessage(handle, WM_KEYUP, 0, 0);  // close child windows
		}
		return true;
	}
	*/

private:
	MainView * mainView; 
	Model * model ;
	//static int vk_value; 
};

#endif
